// token
// var jwt=require('jsonwebtoken')
var jwt = require('koa-jwt')
var {secret} = require('../config')


var router = require('koa-router')()
router.prefix('/questions')
const {
    checkQuestionExist,
    checkQuestioner,
    find,
    findById,
    create,
    update,
    remove
} = require('../controllers/questions')

const auth = jwt({secret})


// 查询问题列表
router.get('/', find)
// 查询特定问题
router.get('/:id', checkQuestionExist, findById)
// 创建问题
router.post('/', auth, create)
// 更新问题
router.patch('/:id', auth, checkQuestionExist, checkQuestioner, update)
// 删除问题
router.delete('/:id', auth, checkQuestionExist, checkQuestioner, remove)


module.exports = router
